home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
UTIL
/
SCREEN
/
CURSES01
/
minix
/
c
/
update
< prev
next >
Wrap
Text File
|
1991-05-05
|
9KB
|
281 lines
/****************************************************************/
/* Doupdate() routine of the PCcurses package */
/* */
/****************************************************************/
/* This version of curses is based on ncurses, a curses version */
/* originally written by Pavel Curtis at Cornell University. */
/* I have made substantial changes to make it run on IBM PC's, */
/* and therefore consider myself free to make it public domain. */
/* Bjorn Larsson (...mcvax!enea!infovax!bl) */
/****************************************************************/
/* 1.0: Release: 870515 */
/****************************************************************/
/* Modified to run under the MINIX operating system by Don Cope */
/* These changes are also released into the public domain. */
/* 900906 */
/****************************************************************/
#include <stdio.h>
#include <curses.h>
#include "curspriv.h"
static void clrupdate(); /* fwd declaration */
static bool transformline();
static void clearscreen();
static void gotoxy();
static void Putchar();
static WINDOW *twin; /* used by many routines */
#ifndef MINIX
static char atrtab[U[64] = /* attribute encoding table. */
{ /* feel free to edit if your */
07, /* NORMAL (0) */ /* display board supports all */
0x87, /* BLINK */ /* possible combinations */
0, /* BLANK */
0, /* BLINK & BLANK */
0x0f, /* BOLD */
0x8f, /* BOLD & BLINK */
0, /* BOLD & BLANK */
0, /* BOLD & BLINK & BLANK */
0x70, /* REVERSE (8) */
0xf0, /* REVERSE & BLINK */
0, /* REVERSE & BLANK */
0, /* REVERSE & BLINK & BLANK */
0x78, /* REVERSE & BOLD */
0xf8, /* REVERSE & BOLD & BLINK */
0, /* REVERSE & BOLD & BLANK */
0, /* REVERSE & BOLD & BLINK & BLANK */
0x70, /* STANDOUT (10) */
0x8f, /* STANDOUT & BLINK */
0, /* STANDOUT & BLANK */
0, /* STANDOUT & BLINK & BLANK */
0x0f, /* STANDOUT & BOLD */
0x8f, /* STANDOUT & BOLD & BLINK */
0, /* STANDOUT & BOLD & BLANK */
0, /* STANDOUT & BOLD & BLINK & BLANK */
0x70, /* STANDOUT & REVERSE (18) */
0xf0, /* STANDOUT & REVERSE & BLINK */
0, /* STANDOUT & REVERSE & BLANK */
0, /* STANDOUT & REVERSE & BLINK & BLANK */
0x70, /* STANDOUT & REVERSE & BOLD */
0xf0, /* STANDOUT & REVERSE & BOLD & BLINK */
0, /* STANDOUT & REVERSE & BOLD & BLANK */
0, /* STANDOUT & REVERSE & BOLD & BLINK & BLANK */
1, /* UNDERLINE (20) */
0x81, /* UNDERLINE & BLINK */
0, /* UNDERLINE & BLANK */
0, /* UNDERLINE & BLINK & BLANK */
9, /* UNDERLINE & BOLD */
0x89, /* UNDERLINE & BOLD & BLINK */
0, /* UNDERLINE & BOLD & BLANK */
0, /* UNDERLINE & BOLD & BLINK & BLANK */
0x70, /* UNDERLINE & REVERSE (28) */
0xf0, /* UNDERLINE & REVERSE & BLINK */
0, /* UNDERLINE & REVERSE & BLANK */
0, /* UNDERLINE & REVERSE & BLINK & BLANK */
0x79, /* UNDERLINE & REVERSE & BOLD */
0xf9, /* UNDERLINE & REVERSE & BOLD & BLINK */
0, /* UNDERLINE & REVERSE & BOLD & BLANK */
0, /* UNDERLINE & REVERSE & BOLD & BLINK & BLANK */
9, /* UNDERLINE & STANDOUT (30) */
0x89, /* UNDERLINE & STANDOUT & BLINK */
0, /* UNDERLINE & STANDOUT & BLANK */
0, /* UNDERLINE & STANDOUT & BLINK & BLANK */
9, /* UNDERLINE & STANDOUT & BOLD */
0x89, /* UNDERLINE & STANDOUT & BOLD & BLINK */
0, /* UNDERLINE & STANDOUT & BOLD & BLANK */
0, /* UNDERLINE & STANDOUT & BOLD & BLINK & BLANK */
0x70, /* UNDERLINE & STANDOUT & REVERSE (38) */
0xf0, /* UNDERLINE & STANDOUT & REVERSE & BLINK */
0, /* UNDERLINE & STANDOUT & REVERSE & BLANK */
0, /* UNDERLINE & STANDOUT & REVERSE & BLINK & BLANK */
0x70, /* UNDERLINE & STANDOUT & REVERSE & BOLD */
0xf0, /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLINK */
0, /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLANK */
0, /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLINK & BLANK */
};
#endif
/****************************************************************/
/* Doupdate() updates the physical screen to look like _curs- */
/* var.tmpwin if curscr is not 'Clear-marked'. Otherwise it */
/* updates the screen to look like curscr. */
/****************************************************************/
void doupdate()
{
register int i;
twin = _cursvar.tmpwin;
if (curscr->_clear)
clrupdate(curscr);
else
{
if (twin->_clear)
clrupdate(twin);
else
{
for (i=0; i < LINES; i++)
if (twin->_minchng[i] != _NO_CHANGE)
if (transformline(i))
break;
} /* else */
} /* else */
curscr->_curx = twin->_curx;
curscr->_cury = twin->_cury;
gotoxy(curscr->_cury, curscr->_curx);
fflush(stdout);
} /* doupdate */
/****************************************************************/
/* Clrupdate(scr) updates the screen by clearing it and then */
/* redraw it in it's entirety. If _cursvar.refrbrk is TRUE, and */
/* there is pending input characters, the update will be pre- */
/* maturely terminated. */
/****************************************************************/
static void clrupdate(scr)
WINDOW *scr;
{
register int *src;
register int *dst;
register int i;
register int j;
static WINDOW *w;
w = curscr;
if (scr != w) /* copy scr to curscr */
{
for (i=0; i < LINES; i++)
{
src = scr->_line[i];
dst = w->_line[i];
for (j=0; j < COLS; j++)
*dst++ = *src++;
} /* for */
} /* if */
clearscreen(); /* clear physical screen */
scr->_clear = FALSE;
for (i=0; i < LINES; i++) /* update physical screen */
{
src = w->_line[i];
j=0;
while(j < COLS)
{
if (*src != (' ' | ATR_NRM))
{
gotoxy(i,j);
while (j<COLS && (*src != (' ' | ATR_NRM)))
{
Putchar(scr, *src++);
j++;
}
}
else
{
src++;
j++;
}
} /* for */
if(_cursvar.refrbrk && _cursespendch())
return;
} /* for */
fflush(stdout);
} /* clrupdate */
/****************************************************************/
/* Transformline() updates the given physical line to look */
/* like the corresponding line in _cursvar.tmpwin. Transform- */
/* returns 1 if premature refresh end is allowed, and there is */
/* an input character pending. */
/****************************************************************/
static bool transformline(lineno)
register int lineno;
{
register int *dstp;
register int *srcp;
register int *dstc;
register int *srcc;
static int x;
static int endx;
x = twin->_minchng[lineno];
endx = twin->_maxchng[lineno];
dstp = curscr->_line[lineno] + x;
srcp = twin->_line[lineno] + x;
dstc = curscr->_colors;
srcc = twin->_colors;
while (x <= endx)
{
if((*dstp != *srcp) || (*dstc != *srcc))
{
gotoxy(lineno,x);
while (x<= endx && ((*dstp != *srcp) || (*dstc != *srcc)))
{
Putchar(twin, *srcp);
*dstp++ = *srcp++;
x++;
}
}
else
{
*dstp++ = *srcp++;
x++;
}
} /* for */
twin->_minchng[lineno] = _NO_CHANGE;
twin->_maxchng[lineno] = _NO_CHANGE;
return (_cursvar.refrbrk && _cursespendch());
} /* transformline */
/****************************************************************/
/* Clearscreen() clears the physical screen and puts the cursor */
/* in the home position. */
/****************************************************************/
static void clearscreen()
{
_cursesclrscr();
gotoxy(0,0);
} /* clearscreen */
/****************************************************************/
/* Gotoxy() moves the physical cursor to the desired address on */
/* the screen. We don't optimize here - on a PC, it takes more */
/* time to optimize than to do things directly. */
/****************************************************************/
static void gotoxy(row,col)
int row, col;
{
if((_cursvar.cursrow == row) && (_cursvar.curscol == col))
return;
_cursescursor(0,row,col);
_cursvar.cursrow = row;
_cursvar.curscol = col;
} /* gotoxy */
/****************************************************************/
/* Putchar() writes a character, with attributes, to the physi- */
/* cal screen, but avoids writing to the lower right screen */
/* position. */
/****************************************************************/
static void Putchar(win, ch)
WINDOW *win;
int ch;
{
if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS))
#ifdef MINIX
_cursessetcolor(win->_colors);
_cursescattr(0,ch,ch >> 8, 0);
#else
_cursescattr(0,ch,atrtab[(ch >> 8) & 0x3f],1);
#endif
} /* Putchar */